package gui;
/**
 * Responsible for drawing and controlling all the graphical elements of the
 * Statistics menu
 */
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JProgressBar;
import javax.swing.SwingConstants;

import controller.StatisticsController;

public class StatisticsDisplay extends Display {
	
	private StatisticsController statisticsController;
	JLabel lblUsername_2;	
	JLabel lblBank;
	JLabel lblExpPoints;
	JLabel lblRankName;
	JLabel lblNextRankExp;
	JLabel lblHandsPlayed_1;
	JLabel lblHandsWon_1;
	JLabel lblHandsLost_1;
	JLabel lblWon;
	JProgressBar progressBar;
	
	/**
	 * Creates a new StatisticsDisplay and links it with a StatisticsController
	 * @param c Controller to be linked
	 */
	public StatisticsDisplay(StatisticsController c) {
		super();
		drawStatistics();
		this.statisticsController = c;
	}
	
	/**
	 * Creates a new StatisticsDisplay and links it with a StatisticsController
	 * and a Display
	 * @param c Contoller to be linked
	 * @param lastDisplay Display to be linked
	 */
	public StatisticsDisplay(StatisticsController c, Display lastDisplay) {
		super(lastDisplay.getFrame());
		drawStatistics();
		this.statisticsController = c;
	}
	
	/**
	 * Draws all the UI elements and defines functionality of the settings
	 * menu
	 */
	public void drawStatistics() {
		frame.getContentPane().removeAll();
		
		ImagePanel STATS = new ImagePanel(new ImageIcon(GUI.class.getResource("/images/Menu_BG_V3.png")).getImage());
		STATS.setBackground(Color.BLACK);
		frame.getContentPane().add(STATS, "name_773741260127683");
		STATS.setLayout(null);
		
		lblUsername_2 = new JLabel("");
		lblUsername_2.setHorizontalAlignment(SwingConstants.CENTER);
		lblUsername_2.setFont(new Font("Tahoma", Font.PLAIN, 26));
		lblUsername_2.setForeground(Color.WHITE);
		lblUsername_2.setBounds(0, 25, 627, 69);
		STATS.add(lblUsername_2);
		
		JLabel lblCredit = new JLabel("Credit:");
		lblCredit.setForeground(Color.WHITE);
		lblCredit.setBounds(160, 101, 56, 16);
		STATS.add(lblCredit);
		
		lblBank = new JLabel("");
		lblBank.setHorizontalAlignment(SwingConstants.RIGHT);
		lblBank.setForeground(Color.WHITE);
		lblBank.setBounds(415, 101, 56, 16);
		STATS.add(lblBank);
		
		JLabel lblRanking = new JLabel("Ranking:");
		lblRanking.setForeground(Color.WHITE);
		lblRanking.setBounds(160, 130, 56, 16);
		STATS.add(lblRanking);
		
		lblRankName = new JLabel("");
		lblRankName.setHorizontalAlignment(SwingConstants.RIGHT);
		lblRankName.setForeground(Color.WHITE);
		lblRankName.setBounds(370, 130, 101, 16);
		STATS.add(lblRankName);
		
		JLabel lblExperiencePoints = new JLabel("Experience Points:");
		lblExperiencePoints.setForeground(Color.WHITE);
		lblExperiencePoints.setBounds(160, 157, 125, 16);
		STATS.add(lblExperiencePoints);
		
		lblExpPoints = new JLabel("");
		lblExpPoints.setHorizontalAlignment(SwingConstants.RIGHT);
		lblExpPoints.setForeground(Color.WHITE);
		lblExpPoints.setBounds(370, 157, 101, 16);
		STATS.add(lblExpPoints);
		
		JLabel lblPointsToNext = new JLabel("Points to next Rank:");
		lblPointsToNext.setForeground(Color.WHITE);
		lblPointsToNext.setBounds(160, 186, 134, 16);
		STATS.add(lblPointsToNext);
		
		lblNextRankExp = new JLabel("");
		lblNextRankExp.setHorizontalAlignment(SwingConstants.RIGHT);
		lblNextRankExp.setForeground(Color.WHITE);
		lblNextRankExp.setBounds(346, 186, 125, 16);
		STATS.add(lblNextRankExp);
		
		progressBar = new JProgressBar(0, 100);
		progressBar.setForeground(new Color(255,210,101));
		progressBar.setBackground(Color.LIGHT_GRAY);
		progressBar.setBounds(160, 215, 311, 16);
		STATS.add(progressBar);
		
		JLabel lblHandsPlayed = new JLabel("Hands Played:");
		lblHandsPlayed.setForeground(Color.WHITE);
		lblHandsPlayed.setBounds(160, 261, 88, 16);
		STATS.add(lblHandsPlayed);
		
		lblHandsPlayed_1 = new JLabel("");
		lblHandsPlayed_1.setHorizontalAlignment(SwingConstants.RIGHT);
		lblHandsPlayed_1.setForeground(Color.WHITE);
		lblHandsPlayed_1.setBounds(346, 261, 125, 16);
		STATS.add(lblHandsPlayed_1);
		
		JLabel lblHandsWon = new JLabel("Hands Won:");
		lblHandsWon.setForeground(Color.WHITE);
		lblHandsWon.setBounds(160, 290, 88, 16);
		STATS.add(lblHandsWon);
		
		lblHandsWon_1 = new JLabel("");
		lblHandsWon_1.setHorizontalAlignment(SwingConstants.RIGHT);
		lblHandsWon_1.setForeground(Color.WHITE);
		lblHandsWon_1.setBounds(370, 290, 101, 16);
		STATS.add(lblHandsWon_1);
		
		JLabel lblHandsLost = new JLabel("Hands Lost:");
		lblHandsLost.setForeground(Color.WHITE);
		lblHandsLost.setBounds(160, 319, 88, 16);
		STATS.add(lblHandsLost);
		
		lblHandsLost_1 = new JLabel("");
		lblHandsLost_1.setHorizontalAlignment(SwingConstants.RIGHT);
		lblHandsLost_1.setForeground(Color.WHITE);
		lblHandsLost_1.setBounds(370, 319, 101, 16);
		STATS.add(lblHandsLost_1);
		
		JLabel lblWinningPercentage = new JLabel("Winning Percentage:");
		lblWinningPercentage.setForeground(Color.WHITE);
		lblWinningPercentage.setBounds(160, 348, 134, 16);
		STATS.add(lblWinningPercentage);
		
		lblWon = new JLabel("");
		lblWon.setHorizontalAlignment(SwingConstants.RIGHT);
		lblWon.setForeground(Color.WHITE);
		lblWon.setBounds(415, 348, 56, 16);
		STATS.add(lblWon);
		
		JButton btnReturnToMain = new JButton("Return to Main Menu");
		btnReturnToMain.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				statisticsController.returnToLobby();
			}
		});
		btnReturnToMain.setBounds(238, 420, 152, 28);
		STATS.add(btnReturnToMain);
		
		frame.setVisible(true);

	}
	
	/**
	 * Updates username field
	 * @param username username to change
	 */
	public void updateUsername(String username) {
		lblUsername_2.setText(username+"'s statistics");
	}
	
	/**
	 * Updates bank field
	 * @param bank bank value to change
	 */
	public void updateBank(int bank){
		lblBank.setText(""+bank);
	}
	
	/**
	 * Updates rank field
	 * @param rank rank value to change
	 */
	public void updateRank(String rank){
		lblRankName.setText(""+rank);
	}
	
	/**
	 * Updates exp field
	 * @param exp exp value to change
	 */
	public void updateExp(int exp){
		lblExpPoints.setText(""+exp);
	}
	
	/**
	 * Updates the exp to the next level
	 * @param exp exp value to change
	 */
	public void updateNextExp(int exp){
		lblNextRankExp.setText(""+exp);
	}
	
	/**
	 * Updates number of hands played
	 * @param games value of games to change
	 */
	public void updateHandsPlayed(int games){
		lblHandsPlayed_1.setText(""+games);
	}
	/**
	 * Updates number of hands won
	 * @param games number of hands to update to
	 */
	public void updateHandsWon(int games){
		lblHandsWon_1.setText(""+games);
	}
	/**
	 * Updates number of hands lost
	 * @param games value of hands lost
	 */
	public void updateHandsLost(int games){
		lblHandsLost_1.setText(""+games);
	}
	
	/**
	 * Updates win percentage
	 * @param percent New win percentage to update to
	 */
	public void updatePercentage(double percent){
		lblWon.setText(""+percent);
	}
	
	/**
	 * Updates the progress bar
	 * @param exp Sets the current exp level
	 * @param expUp Sets the exp to next level
	 */
	public void setProgress(double exp, double expUp){
			progressBar.setValue((int)(100*exp/expUp));
	}
}
